package tech.aistar.controller.mycat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.aistar.entity.mycat.CodeStatus;
import tech.aistar.entity.mycat.Result;
import tech.aistar.entity.personal.User;
import tech.aistar.service.personal.IUserService;



/**
 * Created by Administrator on 2019/9/26.
 */
@Controller
@RequestMapping("/user")
public class RegisterController {
    @Autowired
    private IUserService userService;

    /**
     * Restful
     *
     * @return
     */
    @GetMapping
    public @ResponseBody
    Result checkUser(User user) {
        User u = userService.findByName(user.getUsername());
        if (null == u) {
            return new Result(CodeStatus.OK, true, "用户名可用", u);
        }
        return new Result(CodeStatus.ERROR, false, "用户名重复", u);
    }

    @RequestMapping("/registerAction")
    public String registerAction(User user) {
        System.out.println(user);
        userService.save(user);


        return "../../index";


    }


    /**
     * 转发到prj/user/login.jsp
     */
    @GetMapping("/register")
    public String registerview() {
        return "user/register";
    }
}
